package com.springboot.ww.platform.pd.dto;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Function;

/**
 * tt店铺实体类
 *
 * @author lijinghua
 * @date 2022-03-08
 */
@Data
@Slf4j
public class PdStoreTokenVO {
    private String storeCode;
    private String siteCode;
    private String account;
    private String token;
    private String tokenGlobal;
    private String appKey;
    private String appSecret;
    private String tokenCn;
    private String appKeyCn;
    private String appSecretCn;
    private String apiUrl;
    private String currency;
    /**
     * 是否美区
     */
    private Boolean isUs;
    private String doMain;
    private String realDoMain;


    public static Function<AuthParamValueVO, PdStoreTokenVO> builder() {
        return (authParamValueVO) -> {
            PdStoreTokenVO vo = new PdStoreTokenVO();
            vo.setAccount(authParamValueVO.getName());
            vo.setSiteCode(authParamValueVO.getSiteCode());
            vo.setStoreCode(authParamValueVO.getCode());
            vo.setToken(authParamValueVO.getToken());
            vo.setApiUrl(authParamValueVO.getApiUrl());
            vo.setAppKey(authParamValueVO.getParamMap().get("appKey"));
            vo.setAppSecret(authParamValueVO.getParamMap().get("appSecret"));
            vo.setTokenCn(authParamValueVO.getParamMap().get("tokenCn"));
            vo.setTokenGlobal(authParamValueVO.getParamMap().get("tokenGlobal"));
            vo.setAppKeyCn(authParamValueVO.getParamMap().get("appKeyCn"));
            vo.setAppSecretCn(authParamValueVO.getParamMap().get("appSecretCn"));
            vo.setDoMain(authParamValueVO.getParamMap().get("doMain"));
            String currency = authParamValueVO.getParamMap().get("currency");
            vo.setCurrency(ObjectUtil.isNotEmpty(currency) ? currency : null);
            vo.setIsUs(false);
            if(ObjectUtil.isEmpty(vo.getAppKeyCn()) || vo.getAppKeyCn().equals(vo.getAppKey())){
                vo.setIsUs(true);
            }
            log.info("pdd抓单店铺鉴权信息{} ", JSON.toJSONString(vo));
            return vo;
        };
    }
}
